package com.sk.bilibili.adapter.pager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

public abstract class BaseFragmentAdapter extends FragmentPagerAdapter {

    public BaseFragmentAdapter(@NonNull FragmentManager fm) {
        super(fm);
    }

    /**
     * 主页必须手动调用 初始化
     */
    protected void initData(){
        fragments=getFragments();
        titles=getTitles();
    }

    protected abstract String[] getTitles();

    protected abstract Fragment[] getFragments();

    private Fragment[] fragments;
    private String[] titles;

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        return fragments[position];
    }

    @Override
    public int getCount() {
        return titles.length;
    }

}